package org.icnmasjid.member.dao.hibernate;

import java.util.List;

import org.icnmasjid.member.dao.LookupDao;
import org.icnmasjid.member.model.PaymentCategory;
import org.icnmasjid.member.model.RelationshipType;
import org.icnmasjid.member.model.Role;
import org.icnmasjid.member.model.SubOrg;


/**
 * Hibernate implementation of LookupDao.
 *
 * <p><a href="LookupDaoHibernate.java.html"><i>View Source</i></a></p>
 *
 * @author <a href="mailto:matt@raibledesigns.com">Matt Raible</a>
 */
public class LookupDaoHibernate extends BaseDaoHibernate implements LookupDao {

    /**
     * @see org.icnmasjid.member.dao.LookupDao#getRoles()
     */
    public List getRoles() {
        log.debug("retrieving all role names...");

        return getHibernateTemplate().find("from Role order by name");
    }
    
    public Role getRoleByName(String name) {
    	Object[] values = new Object[]{name.toLowerCase()};
    	return (Role)getHibernateTemplate().find("from Role r where lower(r.name) = ?", values).get(0);
    }
    
    public SubOrg getSubOrgByName(String name) {
    	Object[] values = new Object[]{name.toLowerCase()};
    	return (SubOrg)getHibernateTemplate().find("from SubOrg r where lower(r.name) = ?", values).get(0);
    }
    
    public RelationshipType getRelationShipTypeByName(String name) {
    	Object[] values = new Object[]{name.toLowerCase()};
    	return (RelationshipType)getHibernateTemplate().find("from RelationshipType r where lower(r.relationshipType) = ?", values).get(0);    	
    }
    
    public List<PaymentCategory> getPaymentCategories() {
    	return getHibernateTemplate().find("from PaymentCategory order by name");    	
    }
}